﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ControlFocusWin.Util
{
    /// <summary>
    /// 屏幕相关公共类
    /// </summary>
    public class ScreenUtil
    { 
        /// <summary>
        /// 获取控件显示可见像素比例
        /// </summary>
        /// <returns></returns>
        public static ScreenScale ZoomScale()
        {
            ScreenScale scale = new ScreenScale() { XScale = 1, YScale = 1 };
            int DpiPercent = 96;
            using (System.Drawing.Graphics currentGraphics = System.Drawing.Graphics.FromHwnd((IntPtr)0))
            {
                double dpiXRatio = currentGraphics.DpiX / DpiPercent;
                double dpiYRatio = currentGraphics.DpiY / DpiPercent;

                //比率小于0.001没有意义； 1/96 既1px就是可见的1px
                scale.XScale = dpiXRatio <= 0.001 ? 1 : dpiXRatio;
                scale.YScale = dpiYRatio <= 0.001 ? 1 : dpiYRatio;
            }

            return scale;
        }
    }

    /// <summary>
    /// 屏幕视角可见比例
    /// </summary>
    public struct ScreenScale
    {
        public double XScale; // X轴比例
        public double YScale; // Y轴比例
    }
}
